package com.leyou.trade.web;

import com.leyou.trade.dto.OrderDTO;
import com.leyou.trade.dto.OrderVO;
import com.leyou.trade.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author YYP
 * @date 2021/1/15
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param orderDTO 订单数据
     * @return 订单id
     */
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderDTO orderDTO) {

        return ResponseEntity.status(HttpStatus.CREATED).body( this.orderService.createOrder(orderDTO));
    }

    /**
     * 根据订单号查询订单
     * @param orderId
     * @return
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderVO> queryOrderByOId(@PathVariable("id") Long orderId){
        return ResponseEntity.status(HttpStatus.CREATED).body(this.orderService.queryOrderByOId(orderId));
    }

    /**
     * 查询订单支付状态
     * @param orderId 订单id
     * @return 状态值
     */
    @GetMapping("/status/{id}")
    public ResponseEntity<Integer> queryOrderState(@PathVariable("id") Long orderId) {
        return ResponseEntity.status(HttpStatus.CREATED).body(orderService.queryOrderState(orderId));
    }
}
